//
//  FocusChannels.m
//  YZZX
//
//  Created by Easaa on 15/6/15.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "FocusChannels.h"
#import "ControlzhuceView.h"

@interface FocusChannels ()<HXHttpRequestDelegate,UIScrollViewDelegate>
{
    HXHttpRequest *_httpRequest;            //请求
    NSMutableArray *ArryDataCategory;
    
    NSInteger  TagCount;
    UIScrollView  *_BgScrollView;

}

@end

@implementation FocusChannels

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"关注";
    TagCount = 0;
    
    

    ArryDataCategory = [[NSMutableArray alloc]init];
    
    //列表请求  参数为 用户ID  、 用户账号
    NSDictionary* dicParamsCategory = [NSDictionary dictionaryWithObjectsAndKeys:
                                       [XSZ_UICommon useridChangUaerdfLoginBoolString],                   @"user_id",
                                       @"1",                   @"site_id",nil];
    
    
    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParamsCategory andMethod:YZ_CATEGORY_LIST andTag:1002];
    
    
  
}

- (void)viewWillAppear:(BOOL)animated;
{
     [super viewWillAppear:animated];
    //隐藏返回按钮
    self.NavBack.hidden =YES;

}


- (void)crewatList
{
    UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, Dev_ScreenWidth-20, 60)];
    labelTitle.font = [UIFont boldSystemFontOfSize:18.0f];  //UILabel的字体大小
    labelTitle.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    labelTitle.textColor = [UIColor blackColor];//RGBCOLOR(0, 0, 147);
    labelTitle.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
//    [labelTitle setBackgroundColor:[UIColor greenColor]];
    labelTitle.text =@"初次登录，请选择您所关注的频道";
    [self.view addSubview:labelTitle];
    
    // UIScrollView创建
    _BgScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 60, Dev_ScreenWidth, Dev_ScreenHeight-64-60-70)];
    _BgScrollView.contentSize =CGSizeMake(Dev_ScreenWidth, ArryDataCategory.count*70);
    _BgScrollView.delegate =self;
    //_BgScrollView.bounces = NO;
    [_BgScrollView setPagingEnabled:YES];
    //[_BgScrollView setShowsHorizontalScrollIndicator:NO];
    _BgScrollView.showsHorizontalScrollIndicator = NO;
    _BgScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_BgScrollView];
    
//    _BgScrollView.backgroundColor =[UIColor redColor];
    
    
    for (int i = 0;i<ArryDataCategory.count;i++)
    {
        CategoryDataModel *CategoryModel = ArryDataCategory[i];
        ControlzhuceView  *ViewList =[[ControlzhuceView alloc]initWithFocusc:CGRectMake(10, i*60+10*i+10, Dev_ScreenWidth-20, 60)];
        ViewList.tag = i;
        [ViewList addTarget:self action:@selector(contlrFantion:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [ViewList.layer setMasksToBounds:YES];
        [ViewList.layer setCornerRadius:3]; //设置矩圆角半径
        [ViewList.layer setBorderWidth:1.0];   //边框宽度
        CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 0, 0, 0, 0.5 });
        [ViewList.layer setBorderColor:colorref];//边框颜色
        if(i == 0)
        {
            ViewList.backgroundColor =RGBCOLOR(245, 206, 213);
        }
        
        
        ViewList.LableTitle.text = CategoryModel.cate_name;
        [ViewList.imageViewTitle sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.hellomommy.cn%@",CategoryModel.image_url]] placeholderImage:[UIImage imageNamed:@"bg"]];
        [_BgScrollView addSubview:ViewList];
    }
    
    
    UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    bottomButton.tag = 2014 ;
    bottomButton.frame =CGRectMake(10,Dev_ScreenHeight-64-60 ,Dev_ScreenWidth-20, 40);
    [bottomButton addTarget:self action:@selector(FocuisFantion) forControlEvents:UIControlEventTouchUpInside];
    [bottomButton.layer setMasksToBounds:YES];
    [bottomButton.layer setCornerRadius:2]; //设置矩圆角半径
    [bottomButton.layer setBorderWidth:0];   //边框宽度
    [bottomButton setTitle:@"马上去看看" forState:UIControlStateNormal];
    [bottomButton setTintColor:[UIColor whiteColor]];
    bottomButton.backgroundColor =RGBCOLOR(252, 78, 125);
    [self.view addSubview:bottomButton];

}
- (void)FocuisFantion
{
    //切换视图
    [self.delegatViewroot ChangMainViewContorllerDataAndUIModelTag:TagCount];
    
    //创建通知
    NSString *strtag =[NSString stringWithFormat:@"%d",TagCount];
    NSDictionary *dicD =[[NSDictionary alloc]initWithObjectsAndKeys:strtag,@"Tag", nil];
    
    NSNotification *notification =[NSNotification notificationWithName:YZZX_LEFT_CELL_CHANG object:nil userInfo:dicD];
    //通过通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:notification];


    NSUserDefaults *UserDefaultSize =[NSUserDefaults standardUserDefaults];
    [UserDefaultSize setInteger:TagCount forKey:YZZX_guanzhu_pindao];
    [self.navigationController popToRootViewControllerAnimated:YES];

    
    

}

- (void)contlrFantion:(UIControl*)control
{
    for(UIView  *viewaa in _BgScrollView.subviews)
    {
       if([viewaa isKindOfClass:[ControlzhuceView class]])
       {
           viewaa.backgroundColor =[UIColor whiteColor];
       }
    }

    control.backgroundColor = RGBCOLOR(245, 206, 213);
    TagCount = control.tag;
}

#pragma mark Http request delegate
- (void)requestFinished:(NSString *)responseString andStatusCode:(int)statusCode andTag:(NSInteger)tag
{
    
  
        
        //NSLog(@"---------------->>>> %@",responseString);
        
        NSDictionary *DicJosn = [[NSDictionary alloc]init];
        DicJosn = [JsonUtil jsonToDic:responseString];
        
        //  NSLog(@"---------------->>>> \n%@",dic);
        
        
        NSString * strs = DicJosn[@"data"];
        NSDictionary *dicData =[JsonUtil jsonToDic:strs];
        
        
        NSArray *arryy =(NSArray *)dicData;
        
        [ArryDataCategory removeAllObjects];
    
        for (NSDictionary *dicModel in arryy) {
            
            CategoryDataModel *CategoryModel =[[CategoryDataModel alloc]init];
            CategoryModel.image2_url =[dicModel objectForKey:@"image2_url"];
            CategoryModel.cate_name  =[dicModel objectForKey:@"cate_name"];
            CategoryModel.children   =[dicModel objectForKey:@"children"];
            CategoryModel.cate_id    =[dicModel objectForKey:@"cate_id"];
            CategoryModel.page_type  =[dicModel objectForKey:@"page_type"];
            CategoryModel.image_url  =[dicModel objectForKey:@"image_url"];
            CategoryModel.config     =[dicModel objectForKey:@"config"];
            CategoryModel.cate_type  =[dicModel objectForKey:@"cate_type"];
            
            
            [ArryDataCategory addObject:CategoryModel];
            NSLog(@"---------00------->>>> %@",[dicModel objectForKey:@"cate_name"]);
            
        }
        
    
    [self crewatList];
    
}




- (void)requestFailed:(NSError *)error andTag:(NSInteger)tag
{
    
    
    
    
    
}




@end
